﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TencentCloud.Common;
using TencentCloud.Common.Profile;
using TencentCloud.Nlp.V20190408;
using TencentCloud.Nlp.V20190408.Models;

namespace MyQQRobot
{
    public class MyNPL
    {
        public static Credential cred = new Credential
        {
            SecretId = "AKIDue7JEtIQHrADzXqtfAOL2TdX9UYLs75m",
            SecretKey = "ScV7SVHm0yg7G9k46sNaW7SVHlzwc1A5"
        };
        public static WordMatchResponse wordMatch(String srcText,String[] targetText)
        {
            WordMatchResponse wordMatchResponse=null;
            try
            {

                ClientProfile clientProfile = new ClientProfile();
                HttpProfile httpProfile = new HttpProfile();
                httpProfile.Endpoint = ("nlp.tencentcloudapi.com");
                clientProfile.HttpProfile = httpProfile;

                NlpClient client = new NlpClient(cred, "ap-guangzhou", clientProfile);
                TextSimilarityRequest req = new TextSimilarityRequest();

                req.SrcText = srcText;//测试样例

                req.TargetText = targetText;//提供的样例

                TextSimilarityResponse resp = client.TextSimilaritySync(req);
                String stringResp = AbstractModel.ToJsonString(resp);
                Console.WriteLine(AbstractModel.ToJsonString(resp));

                wordMatchResponse = JsonConvert.DeserializeObject<WordMatchResponse>(stringResp);
                Console.WriteLine("wordMatchResponse.RequestId=" + wordMatchResponse.RequestId);

            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }


            return wordMatchResponse;
        }
        
    }
    public class WordMatchResponse
    {
        public String RequestId;
        public IList<SimilarityInfo> Similarity;
    }

    public class SimilarityInfo
    {
        public double Score;
        public String text;
    }
}
